import request from '@/utils/request'
import { getAgent, getToken, getId } from '@/utils/auth'

export function login(date) {
  const data = {
    username: date.username,
    pwd: date.pwd
  }
  return request ({
    url: 'agent/sales_busin/saleman_login',
    method: 'POST',
    data
  })
}

export function qrCode() {
  return request({
    url: 'agent/sales_busin/create_sales_busin_code',
    method: 'GET'
  })
}

export function salesmanMerchant(page) {
  return request({
    url: 'agent/sales_busin/get_merchant_list',
    method: 'GET',
    params: { page }
  })
}

export function merchanenlChannelWsCategory() {
  return request({
    url: 'agent/sales_busin/ws_category',
    method: 'GET'
  })
}

export function merchanenlChannelPhone(merchant_num) {
  return request({
    url: 'agent/sales_busin/get_mobile',
    method: 'GET',
    params: { merchant_num }
  })
}

export function merchanenlChannelWsMsg(merchant_num) {
  return request({
    url: 'agent/sales_busin/send_ms_code',
    method: 'GET',
    params: { merchant_num }
  })
}

/**
 * 网商通道提交
 */
export function merchanenlChannelWsUpdate(merchant_num, date) {
  return request({
    url: 'agent/sales_busin/apply_channel',
    method: 'POST',
    data: { merchant_num, verify_msg: date.code, address: date.address, area: date.area, industry: date.industry, is_blue: date.is_blue, wx: date.wx_rate, ali: date.ali_rate, balance_type: date.balance_type }
  })
}

export function merchantWsGetInfo(merchant_num) {
  return request({
    url: 'agent/sales_busin/get_channel_info',
    method: 'GET',
    params: { merchant_num }
  })
}

export function GetMerchantInfo(merchant_num) {
  return request({
    url: 'agent/sales_busin/get_merchant_info',
    method: 'GET',
    params: { merchant_num }
  })
}

export function merchant_update(date, merchant_num) {
  const data = {
    merchant_num,
    agent_num: getAgent(),
    sale_num: getId(),
    token: getToken(),
    info: {
      mod: 1,
      type: date.merchant_type,
      full_name: date.full_name,
      short_name: date.short_name,
      service_phone: date.service_phone,
      real_address: date.real_address,
      bus_licence_type: date.bus_licence_type,
      alipay_name: date.alipay_name,
      alipay_account: date.alipay_account,
      bus_licence_no: date.bus_licence_no,
      bus_licence_expire: date.bus_licence_expire,
      bus_licence: date.bus_licence,
      store_face: date.store_face,
      store_canyin_plat: date.store_canyin_plat,
      store_counter: date.store_counter,
      store_space: date.store_space,
      bus_licence_oth: date.bus_licence_oth,
      bus_lease_agreement: date.bus_lease_agreement,
      bus_licence_reg_date: date.bus_licence_reg_date,
    },
    bank: {},
    leader: {},
    contact: {},
    wx: {}
  }
  return request({
    url: 'agent/sales_busin/update_merchant',
    method: 'POST',
    data
  })
}


/**
 * 蓝海行动资料切换
 * @param {Number} merchant_num 商户id
 * @param {Boolean} is_blue 蓝海行动
 */
export function merchanenlChannelWsIsBlue(merchant_num, is_blue) {
  return request({
    url: 'agent/sales_busin/get_wangshang_channel_info',
    method: 'GET',
    params: { merchant_num, is_blue }
  })
}

/**
 * 业务员通道列表各状态
 * @param {Number} merchant_num 商户编号
 */
export function salemanChnnelList(merchant_num) {
  return request({
    url: 'agent/sales_busin/get_h5_channel',
    method: 'GET',
    params: { merchant_num }
  })
}

/**
 * 业务员乐刷通道查看
 */
export function selaemanChannelLeInit(merchant_num) {
  return request({
    url: 'agent/sales_busin/get_query',
    method: 'GET',
    params: { merchant_num }
  })
}

/**
 * 乐刷通道类型查看
 */
export function salemanChannelLeCategory() {
  return request({
    url: 'agent/sales_busin/get_cate_gory',
    method: 'GET'
  })
}

/**
 * 乐刷通道提交
 * @param {Number} merchant_num 商户编号
 * @param {Object} date 商户编号
 */
export function merchantChannelLeUpdate(merchant_num, date) {
  const data = {
    merchant_num,
    area: date.area,
    address: date.address,
    card: date.card,
    mcc: date.mcc,
    mch_short_name: date.store_name,
    balance_type: date.balance_type,
    photo: {
      channel_lepos_place_evid: date.channel_lepos_agreement,
      channel_lepos_netprot: date.channel_lepos_netprot,
      store_licence_hyg: date.store_licence_hyg,
      ch_lpos_certi: date.ch_lpos_certi
    },
    pos_rates: {
      debit: {
        d1: {
          rate: date.debit_d1,
          ceiling: date.debit_money
        },
        d0: {
          rate: date.debit_d0
        }
      },
      credit: {
        d1: {
          rate: date.credit_d1
        },
        d0: {
          rate: date.credit_d0
        }
      },
      ovsea: {
        d1: {
          rate: date.ovsea_d1
        },
        d0: {
          rate: date.ovsea_d0
        }
      }
    },
    rates_t0: { wx: date.wx_t0, ali: date.ali_t0 },
    rates_t1: { wx: date.wx_t1, ali: date.ali_t1 }
  }
  return request({
    url: 'agent/sales_busin/create_lepos_apply',
    method: 'POST',
    data
  })
}
